home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
Advanced I⁄O v2.3
/
ANSI #includes addenda
/
streambuf
< prev
Wrap
Text File
|
1996-02-01
|
5KB
|
165 lines
// streambuf standard header
#ifndef _STREAMBUF_
#define _STREAMBUF_
#include <ios>
#if __MWERKS__
#pragma options align=mac68k
#if __CFM68K__ && __USING_IMPORTED_ANSI__
#pragma import on
#endif
#endif
// macros
#define EOF (-1)
// type streamoff
typedef long streamoff;
const streamoff _BADOFF = -1;
// class streampos
class streampos {
public:
streampos(streamoff = 0, const _Fpost * = 0);
streamoff offset() const;
operator streamoff (void) const { return offset(); }
streamoff operator-(const streampos&) const;
streampos& operator+=(streamoff _O)
{_Pos += _O; return (*this); }
streampos& operator-=(streamoff _O)
{_Pos -= _O; return (*this); }
streampos operator+(streamoff _O) const
{streampos s = *this; s += _O; return s; }
streampos operator-(streamoff _O) const
{streampos s = *this; s -= _O; return s; }
_Bool operator==(const streampos&) const;
_Bool operator!=(const streampos& _R) const
{return (!(*this == _R)); }
_Fpost *_Fpos()
{return (&_Fp); }
private:
streamoff _Pos;
_Fpost _Fp;
};
// class streambuf
class streambuf {
public:
virtual ~streambuf();
virtual int showmany();
streampos pubseekoff(streamoff _O, ios::seekdir _W,
ios::openmode _M = ios::in | ios::out)
{return (seekoff(_O, _W, _M)); }
streampos pubseekoff(streamoff _O, ios::seek_dir _W,
ios::open_mode _M)
{return (pubseekoff(_O, (ios::seekdir)_W, (ios::openmode)_M)); }
streampos pubseekpos(streampos _P,
ios::openmode _M = ios::in | ios::out)
{return (seekpos(_P, _M)); }
streampos pubseekpos(streampos _P, ios::open_mode _M)
{return (seekpos(_P, (ios::openmode)_M)); }
streambuf *pubsetbuf(char *_S, int _N)
{return (setbuf(_S, _N)); }
int pubsync()
{return (sync()); }
int sbumpc()
{return (gptr() != 0 && gptr() < egptr()
? *_Gn()++ : uflow()); }
int sgetc()
{return (gptr() != 0 && gptr() < egptr()
? *_Gn() : underflow()); }
int sgetn(char *_S, int _N)
{return (xsgetn(_S, _N)); }
int snextc()
{return (sbumpc() == EOF ? EOF : sgetc()); }
int sputbackc(char _C)
{return (gptr() != 0 && eback() < gptr()
&& _C == gptr()[-1]
? *--_Gn() : pbackfail((unsigned char)_C)); }
int sungetc()
{return (gptr() != 0 && eback() < gptr()
? *--_Gn() : pbackfail()); }
int sputc(int _C)
{return (pptr() != 0 && pptr() < epptr()
? (*_Pn()++ = _C) : overflow(_C)); }
int sputn(const char *_S, int _N)
{return (xsputn(_S, _N)); }
int in_avail()
{return (gptr() != 0 && gptr() < egptr()
? egptr() - gptr() : showmany()); }
protected:
streambuf()
{_Init(); }
streambuf(ios::_Uninitialized)
{}
char *eback() const
{return (*_IGbeg); }
char *gptr() const
{return (*_IGnext); }
char *egptr() const
{return (*_IGend); }
void gbump(int _N)
{*_IGnext += _N; }
void setg(char *_B, char *_N, char *_E)
{*_IGbeg = _B, *_IGnext = _N, *_IGend = _E; }
char *pbase() const
{return (*_IPbeg); }
char *pptr() const
{return (*_IPnext); }
char *epptr() const
{return (*_IPend); }
void pbump(int _N)
{*_IPnext += _N; }
void setp(char *_B, char *_E)
{*_IPbeg = _B, *_IPnext = _B, *_IPend = _E; }
void setp(char *_B, char *_N, char *_E)
{*_IPbeg = _B, *_IPnext = _N, *_IPend = _E; }
unsigned char *&_Gn()
{return ((unsigned char *&)*_IGnext); }
unsigned char *&_Pn()
{return ((unsigned char *&)*_IPnext); }
virtual int overflow(int = EOF);
virtual int pbackfail(int = EOF);
virtual int underflow();
virtual int uflow();
virtual int xsgetn(char *, int);
virtual int xsputn(const char *, int);
virtual streampos seekoff(streamoff, ios::seekdir,
ios::openmode = ios::in | ios::out);
virtual streampos seekpos(streampos,
ios::openmode = ios::in | ios::out);
virtual streambuf *setbuf(char *, int);
virtual int sync();
void _Init();
void _Init(char **, char **, char **, char **, char **,
char **);
private:
streambuf(const streambuf&); // undefined
streambuf& operator=(const streambuf&); // undefined
char *_Gbeg, *_Gnext, *_Gend;
char *_Pbeg, *_Pnext, *_Pend;
char **_IGbeg, **_IGnext, **_IGend;
char **_IPbeg, **_IPnext, **_IPend;
};
#if __MWERKS__
#if __CFM68K__ && __USING_IMPORTED_ANSI__
#pragma import reset
#endif
#pragma options align=reset
#endif
#endif
/*
* Copyright (c) 1994 by P.J. Plauger. ALL RIGHTS RESERVED.
* Consult your license regarding permissions and restrictions.
*/
/* Change log:
*94June04 PlumHall baseline
*94Sept30 Applied diffs for Fri Aug 26 00:51:20 1994
*94Sept30 Applied diffs for Tue Aug 30 07:28:05 1994
*94Oct07 Inserted MW changes
*94Dec27mm Added in_avail following pjp.
*/